package com.project.common.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: ProjectUtils
 * @Author: kang
 * @Date: 2021/3/19　14:33
 * @Description：项目工具
 */
public final class ProjectUtils {

    private ProjectUtils() {

    }

    //各个端关键字常量
    private final static String ADMIN = "admin";

    private final static String PDA = "pda";

    private final static String APP = "app";

    /**
     * 是否为管理端
     *
     * @return
     */
    public static boolean isAdmin() {
        HttpServletRequest request = ServletUtils.getRequest();
        String url = request.getHeader("Type");
        if (url != null && contains(url, ADMIN, PDA)) {
            return true;
        }
        return false;
    }

    public static boolean contains(String s, String... regs) {
        for (String reg : regs) {
            String[] split = reg.split("\\|");
            for (String s1 : split) {
                if (s.contains(s1)) {
                    return true;
                }
            }
        }
        return false;
    }
}
